<?php
/*
 * 进云智能生成平台
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
 */
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
if($_RQ['op']=='get'){
	$paylogid=$_RQ['paylogid'];
	$paylog=pdo_get('core_paylog',array('id'=>$paylogid,'uniacid'=>$_SESSION['uniacid']));
	$return['title']='下单';
	$member=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit6','mobile','avatar','realname'));
	$return['post']=array(
		'mobile'=>$member['mobile'],
		'name'=>$member['realname'],
		'code'=>$member['cardnum'],
		'bankcode'=>'ABC',
		'paylogid'=>$paylogid,
		'fee'=>$paylog['fee'],
		'paylogtid'=>$paylog['tid'],
	);
	$return['member']=$member;
	$return['paylog']=$paylog;
	$return['banks']=$this->banks;
	set_html('title','在线支付');
	exi($return);
}
if($_RQ['op']=='check'){
	//下单
	$post=get_postdata();
	if(!$post['logid']){
		exi('请先获取验证码！','error');
	}
	if(!$post['smscode']){
		exi('请输入验证码！','error');
	}
	$log=$this->pdo_get('log',array('id'=>$post['logid'],'uniacid'=>$_SESSION['uniacid']));
	$log['sms_code']=$post['smscode'];
	$this->model('pay')->check($log);
	exi('支付成功！');
}
if($_RQ['op']=='topay'){
	//下单
	$post=get_postdata();
	if(!$post['bankcode']){
		exi('请选择银行！','error');
	}
	if(!$post['cardno']){
		exi('请输入银行卡号！','error');
	}
	if(!$post['name']){
		exi('请输入持卡人姓名！','error');
	}
	if(!$post['code']){
		exi('请输入证件号码！','error');
	}
	if(!$post['mobile']){
		exi('请输入签约手机号！','error');
	}
	$log=$this->pdo_get('log',array('paylogid'=>$post['paylogid'],'uniacid'=>$_SESSION['uniacid']));
	if(!$log['id']){
		$log=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'name'=>$post['name'],
			'code'=>$post['code'],
			'mobile'=>$post['mobile'],
			'cardno'=>$post['cardno'],
			'bankcode'=>$post['bankcode'],
			'paylogid'=>$post['paylogid'],
			'paylogtid'=>$post['paylogtid'],
			'fee'=>$post['fee'],
			'createtime'=>TIMESTAMP,
			'status'=>0,
		);
		$this->insert('log',$log);
		$logid=pdo_insertid();
	}else{
		$logid=$log['id'];
	}
	$paylog=pdo_get('core_paylog',array('id'=>$log['paylogid'],'uniacid'=>$_SESSION['uniacid']));
	$log['goodsinfo']=$paylog['title'];
	$hnapayOrderId=$this->model('api')->pay($log);
	if($hnapayOrderId){
		$this->pdo_update('log',array('hnapayorderid'=>$hnapayOrderId),array('id'=>$logid,'uniacid'=>$_SESSION['uniacid']));
	}
	$res=array(
		'logid'=>$logid,
	);
	exi($res);
}
?>